/**
 * @DateTime:     2017-11-05 14:03:52
 * @Description:  解构：使数据访问更便捷
 */
let option = {
  repeat:true,
  save:false
}
let repeat = option.repeat
let save = option.save
/**
 *  对象解构
 */
let node = {
  type:'Indentifier',
  name:'foo'
}

let {type,name} = node
console.log(type)//Indentifier
console.log(name)//foo配置
//----------------------------------------------------------------------------
/**
 *  解构赋值
 */
let job = 'javascript';
let hobby = 'lol';
let funlee = {
  job:'hello',
  hobby:'book'
};       //这里的分号不能少
({job,hobby} = funlee);
console.log(job)
console.log(hobby)
//----------------------------------------------------------------------------
//？？？？？？？？上面的写法报错，下面的写法可以？？？？？？？？？？？？？？？
//                     与数组解构不同
//----------------------------------------------------------------------------
let node = {
  type:'Indentifier',
  name:'foo'
},
type = 'Literal',
name = 'funlee';

({type,name} = node)
console.log(type)
console.log(name)
//----------------------------------------------------------------------------
let node = {
  type:'Indentifier',
  name:'foo'
},
type = 'Literal',
name = 'funlee';
function outputInfo(value) {
  console.log(value)
  console.log(value === node)
}
outputInfo({type,name} = node)

console.log(type)
console.log(name)
//----------------------------------------------------------------------------
/**
 *  默认值 undefind
 */
let node = {
  type:'Indentifier',
  name:'foo'
}
let{type,name,value = '指定默认值'} = node
console.log(type,name,value)
//----------------------------------------------------------------------------
/**
 *  为非同名局部变量赋值
 */
let node = {
  type:'Indentifier',
  name:'foo'
}
let {type:localType,name:localName,value:localValue = '嘿嘿'} = node
console.log(localType,localName,localValue)
//----------------------------------------------------------------------------
/**
 *  嵌套对象解构
 */
let node = {
  type:'Indentifier',
  name:'foo',
  loc:{
    start:{
      line:1,
      column:1
    },
    end:{
      line:1,
      column:4
    }
  }
}
let {loc:{start}} = node // let start = node.loc.start
let {loc:{start:{line:startLine}}} = node
console.log(startLine)
//----------------------------------------------------------------------------
/**
 *  数组解构
 */
let colors = ['red','green','blue']
let [,color1,,color3] = colors
console.log(color1)
console.log(color3)
//----------------------------------------------------------------------------
/**
 *  数组解构赋值
 *  分号  分号 不能少
 */
let colors = ['red','green','blue'];
let color0 = '嘿嘿';
let color1 = '哈哈';//这个分号不能少
[color0,color1] = colors;
console.log(color0)
console.log(color1)
/**
 *  交换变量
 */
let a = 1,b = 2;
[a,b] = [b,a];
console.log(a,b)

let a = 5,b = 8;
a = b - a;
b = b - a;
a = a + b;
console.log(a,b)
//----------------------------------------------------------------------------
/**
 *  数组克隆
 */
let colors = ['red','blue','pink']
let [...cloneColor] = colors;

console.log(cloneColor)
//----------------------------------------------------------------------------
/**
 *  混合解构
 *  从json中提取信息时，不需要再遍历整个解构了
 *  
 */
let node = {
  type:'Indentifier',
  name:'foo',
  loc:{
    start:{
      line:1,
      column:1
    },
    end:{
      line:1,
      column:4
    }
  },
  range:[0,1,2,3]
}
let {loc:{start},range:[startIndex]} = node

console.log(start)
console.log(startIndex)
//----------------------------------------------------------------------------



















